/**
 * 一维数组，形成单select菜单
 * @param json
 * @param select_id 菜单id
 * @param value    作为value的key
 * @param name     作为name 的key
 * @return
 */
function getSelectOne(json,select_id,value,name)
{
	data = json;
	if(typeof(value) == 'undefined')
	{
		value = "id";
	}	
	if(typeof(name) == 'undefined')
	{
		name = "name";
	}	
	$("#"+select_id).empty();
	for(var i in data)
	{
		$("<option value='" + data[i][value] + "'>" + data[i][name] + "</option>").appendTo("#"+select_id);
	}	
}
function getSelectOne_num(json,select_id)
{
	data = JSON.parse(json);
	$("#"+select_id).empty();
	for(var i in data)
	{
		$("<option value='" + i + "'>" + data[i] + "</option>").appendTo("#"+select_id);
	}	
}
/**
 * 需要用到 jquery，json ，data必须符合规定如下,且是json格式。
 * data[0]			  所有的大分类(provinceid=>provincename)
 * data['provinceid'] 对应的小分类(id,name,province)
 * @param main_id
 * @param second_id
 * @param data
 * @return
 */
var TwoSelect_obj = function ()
{
	    
	  	this.city_select = new Array();//只有大分类
	  	this.main_id = '';
	  	this.second_id = '';
	  	this.select_data = new Array();//包括大分类和小分类
	  	
	  	function contract(main_id,second_id,data)
	  	{
	  		this.main_id = main_id;
	  		this.second_id = second_id;
	  		this.select_data = JSON.parse(data);
	  		this.city_select = this.select_data[0];
	  		this.main();
	  	}
  	
	    //初始化大分类
	    this.main = function ()
	    {
	    	 	$("#"+this.main_id).empty();
	    	 	var province_array = this.city_select;
			    for (var j in province_array )
			    {
				    $("<option value='" + j + "'>" + province_array[j] + "</option>").appendTo("#"+this.main_id);
				}  

		 }
	     
		//选择大分类
	     this.main_s = function (s)
	     {
		      if (typeof(s) == 'undefined')
		      {
			     s = $("#"+this.main_id).val();
			      
			  } 
		      this.small(s);       
		 }

		 //初始化小分类
		 this.small = function(s)
		 {
			  if (typeof(s) == 'undefined' || s == 0)
		      {
				  $("#"+this.second_id).empty();
				  return;
			  } 
				$("#"+this.second_id).empty();
				var province_array = this.select_data[s];
			    for (var j in province_array )
			    {
				    $("<option value='" + province_array.id + "'>" + province_array.name + "</option>").appendTo("#"+this.second_id);
				}  
		 }


		
		//根据小分类选项，初始化两个联动下拉
		 this.from_small = function(init_second)
		 {
			 var init_province = 0;
			 var temp;
			 for ( var i in this.select_data)
	     	 {
				 temp = this.select_data[i];
				 for(var j in temp)
				 {
					 if (init_second == temp.id)
			     	{
			     		init_province = temp.province;
			     		break ;
				    }
				 }
		     	
		     }
			this.from_main_small(init_province,init_second);
			    
		 }
		//根据两个初始值，初始联动
		this.from_main_small = function(init_main,init_second)
		{
			$("#"+this.main_id).attr("value",init_main);
			if (init_second == 0)
			 {
				 this.small();
			 }else{
				 this.small(init_main);
			 }
			$("#"+this.second_id).attr("value",init_second);
		}
		 
}
var num_data = '{"0":0,"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"11":11,"12":12,"13":13,"14":14,"15":15,"16":16,"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"33":33,"34":34,"35":35,"36":36,"37":37,"38":38,"39":39,"40":40,"41":41,"42":42,"43":43,"44":44,"45":45,"46":46,"47":47,"48":48,"49":49,"50":50}';

